﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class AlbumTrack : LastfmModelBase, ITrack
    {
        public AlbumTrack()
        {
            this.Rank = 0;
            this.Name = string.Empty;
            this.Duration = 0;
            this.Mbid = string.Empty;
            this.Url = string.Empty;
            this.Streamable = false;
            this.StreamableFulltrack = false;
            this.Artist = new TrackArtist();
        }

        public AlbumTrack(XmlNode albumTrackNode)
        {
            if (albumTrackNode == null) return;
            this.InitializeFromXmlNode(albumTrackNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Rank = node.GetAttributeValue("rank").ToInteger();
            this.Name = node.GetChildValue("name");
            this.Duration = node.GetChildValue("duration").ToInteger();
            this.Mbid = node.GetChildValue("mbid");
            this.Url = node.GetChildValue("url");
            this.Streamable = node.GetChildValue("streamable").ToBoolean();
            this.StreamableFulltrack = node.GetChild("streamable").GetAttributeValue("fulltrack").ToBoolean();
            this.Artist = new TrackArtist(node.GetChild("artist"));
        }

        public int Rank
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }

        public int Duration
        {
            get;
            set;
        }

        public string Mbid
        {
            get;
            set;
        }

        public string Url
        {
            get;
            set;
        }

        public bool Streamable
        {
            get;
            set;
        }

        public bool StreamableFulltrack
        {
            get;
            set;
        }

        public TrackArtist Artist
        {
            get;
            set;
        }
    }
}
